//
//  CTQGDefaultCell.m
//  digitalCurrency
//
//  Created by 默认账户 on 2019/6/2.
//  Copyright © 2019 XinHuoKeJi. All rights reserved.
//

#import "CTQGDefaultCell.h"

@interface CTQGDefaultCell ()
@property (nonatomic, strong) UIView *bgView;
@end

@implementation CTQGDefaultCell

+ (instancetype)createTableView:(UITableView *)tableView {
    
    CTQGDefaultCell *cell = [tableView dequeueReusableCellWithIdentifier:@"qgdefaultcell"];
    cell.selectionStyle  = UITableViewCellSelectionStyleNone;
    cell.backgroundColor = [UIColor whiteColor];
    [cell makeViews];
    
    return cell;
}

- (void)makeViews {
    
    //__weak typeof(self)weakself = self;
    self.layer.masksToBounds = YES;
    self.layer.cornerRadius = 5.0;
    [self.contentView addSubview:self.bgView];
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(2);
        make.top.mas_equalTo(2);
        make.right.mas_equalTo(-2);
        make.bottom.mas_equalTo(-15);
    }];
    
    [self.bgView addSubview:self.titleImgView];
    [self.titleImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(12);
        make.top.mas_equalTo(12);
        make.width.height.mas_equalTo(44);
    }];
    self.titleImgView.hidden = YES;
    
    UIView *topView = [[UIView alloc]init];
    [self addSubview:topView];
    [topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(5);
        make.right.equalTo(-5);
        make.top.equalTo(3);
        make.height.equalTo(42);
    }];
    topView.backgroundColor = [UIColor colorWithHEX:@"#F2FAFD"];
    topView.layer.masksToBounds = YES;
    topView.layer.cornerRadius = 6.0;
    
    [topView addSubview:self.coinName];
    [self.coinName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(18);
        make.centerY.mas_equalTo(0);
    }];
    
    [topView addSubview:self.canUsedCoin];
    [self.canUsedCoin mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.mas_equalTo(0);
    }];
    
    [topView addSubview:self.frozenCoin];
    [self.frozenCoin mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-18);
        make.centerY.mas_equalTo(0);
    }];
    
    CGFloat width4_1 = (SCREEN_WIDTH-84)/3.0;
    
    [self.bgView addSubview:self.rechargeBtn];
    [self.rechargeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(65);
        make.width.mas_equalTo(width4_1);
        make.height.mas_equalTo(32);
        make.left.mas_equalTo(6);
    }];
    
    [self.bgView addSubview:self.redrawBtn];
    [self.redrawBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.top.mas_equalTo(65);
        make.width.mas_equalTo(width4_1);
        make.height.mas_equalTo(32);
    }];
    
    [self.bgView addSubview:self.exchangeBtn];
    [self.exchangeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(width4_1*2.0-0.5);
        make.top.mas_equalTo(65);
        make.width.mas_equalTo(width4_1);
        make.height.mas_equalTo(32);
    }];
    self.exchangeBtn.hidden = YES;
    
    [self.bgView addSubview:self.financeBtn];
    [self.financeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-6);
        make.top.mas_equalTo(65);
        make.width.mas_equalTo(width4_1);
        make.height.mas_equalTo(32);
    }];
    
    
    
}

- (void)redrawClick {
    kPreventRepeatClickTime(1);
    if (self.redrawBlock) {
        self.redrawBlock();
    }
}

- (void)rechargeClick {
    kPreventRepeatClickTime(1);
    if (self.rechargeBlock) {
        self.rechargeBlock();
    }
}

- (void)financeClick {
    kPreventRepeatClickTime(1);
    if (self.financeBlock) {
        self.financeBlock();
    }
}

- (void)exchangeClick {
    kPreventRepeatClickTime(1);
    if (self.exchangeBlock) {
        self.exchangeBlock();
    }
}

- (UIView *)bgView {
    if (!_bgView) {
        _bgView = [[UIView alloc] init];
        _bgView.backgroundColor = [UIColor whiteColor];
        _bgView.layer.cornerRadius = 6;
        _bgView.layer.shadowColor = [UIColor colorWithHEX:@"7E7E7E"].CGColor;
        _bgView.layer.shadowOffset = CGSizeMake(0, 0);
        _bgView.layer.shadowOpacity = 0.21;
    }
    return _bgView;
}

- (UIImageView *)titleImgView {
    if (!_titleImgView) {
        _titleImgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"announce"]];
    }
    
    return _titleImgView;
}

- (UILabel *)coinName {
    if (!_coinName) {
        UILabel *label = [[UILabel alloc] init];
        label.textColor = tThreeColor;
        label.font = [UIFont systemFontOfSize:16];
        
//        NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:@"ONT" attributes:@{NSFontAttributeName: [UIFont fontWithName:@"PingFangSC-Medium" size: 18],NSForegroundColorAttributeName: [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0]}];
//        label.attributedText = string;
        _coinName = label;
    }
    
    return _coinName;
}

- (UILabel *)canUsedCoin {
    if (!_canUsedCoin) {
        UILabel *label = [[UILabel alloc] init];
        label.textColor = [UIColor colorWithHEX:@"#375880"];
        label.font = [UIFont systemFontOfSize:14];
        label.text = LocalizationKey(@"可用:0.00");
//        NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:LocalizationKey(@"可用:0.00") attributes:@{NSFontAttributeName: [UIFont fontWithName:@"PingFangSC-Regular" size: 14],NSForegroundColorAttributeName: [UIColor colorWithRed:246/255.0 green:246/255.0 blue:246/255.0 alpha:1.0]}];
//        label.attributedText = string;
        _canUsedCoin = label;
    }
    
    return _canUsedCoin;
}

- (UILabel *)frozenCoin {
    if (!_frozenCoin) {
        UILabel *label = [[UILabel alloc] init];
        label.textColor = [UIColor colorWithHEX:@"#375880"];
        label.font = [UIFont systemFontOfSize:14];
        label.text = LocalizationKey(@"冻结:0.00");
//        NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:LocalizationKey(@"冻结:0.00") attributes:@{NSFontAttributeName: [UIFont fontWithName:@"PingFangSC-Regular" size: 14],NSForegroundColorAttributeName: [UIColor colorWithRed:247/255.0 green:255/255.0 blue:255/255.0 alpha:1.0]}];
//
//        label.attributedText = string;
        _frozenCoin = label;
    }
    
    return _frozenCoin;
}

- (UIButton *)rechargeBtn {
    if (!_rechargeBtn) {
        _rechargeBtn = [UIButton buttonWithType:UIButtonTypeSystem];
        [_rechargeBtn setTitle:LocalizationKey(@"Recharge") forState:UIControlStateNormal];
        [_rechargeBtn setTitleColor:tNineColor forState:UIControlStateNormal];
        _rechargeBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        [_rechargeBtn addTarget:self action:@selector(rechargeClick) forControlEvents:UIControlEventAllEvents];
        _rechargeBtn.layer.masksToBounds = YES;
        _rechargeBtn.layer.cornerRadius = 5.0;
        _rechargeBtn.layer.borderWidth = 0.5;
        _rechargeBtn.layer.borderColor = tNineColor.CGColor;
    }
    
    return _rechargeBtn;
}

- (UIButton *)redrawBtn {
    if (!_redrawBtn) {
        UIButton *redrawBtn = [UIButton buttonWithType:UIButtonTypeSystem];
        [redrawBtn setTitle:LocalizationKey(@"Withdraw") forState:UIControlStateNormal];
        [redrawBtn setTitleColor:tNineColor forState:UIControlStateNormal];
        redrawBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        [redrawBtn addTarget:self action:@selector(redrawClick) forControlEvents:UIControlEventAllEvents];
        redrawBtn.layer.masksToBounds = YES;
        redrawBtn.layer.cornerRadius = 5.0;
        redrawBtn.layer.borderWidth = 0.5;
        redrawBtn.layer.borderColor = tNineColor.CGColor;
        _redrawBtn = redrawBtn;
    }
    return _redrawBtn;
}

- (UIButton *)exchangeBtn {
    if (!_exchangeBtn) {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
        [btn setTitle:LocalizationKey(@"Convert") forState:UIControlStateNormal];
        [btn setTitleColor:tNineColor forState:UIControlStateNormal];
        btn.titleLabel.font = [UIFont systemFontOfSize:14];
        [btn addTarget:self action:@selector(exchangeClick) forControlEvents:UIControlEventAllEvents];
        
        _exchangeBtn = btn;
    }
    return _exchangeBtn;
}

- (UIButton *)financeBtn {
    if (!_financeBtn) {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
        [btn setTitle:LocalizationKey(@"Financial") forState:UIControlStateNormal];
        [btn setTitleColor:tNineColor forState:UIControlStateNormal];
        btn.titleLabel.font = [UIFont systemFontOfSize:14];
        [btn addTarget:self action:@selector(financeClick) forControlEvents:UIControlEventAllEvents];
        btn.layer.masksToBounds = YES;
        btn.layer.cornerRadius = 5.0;
        btn.layer.borderWidth = 0.5;
        btn.layer.borderColor = tNineColor.CGColor;
        _financeBtn = btn;
    }
    return _financeBtn;
}

@end
